package com.zdsoft.blp.zongbuju.wode.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.zdsoft.blp.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/8/31.
 */
public class GrzxAdapter extends BaseAdapter {

    private List<Map<String,Object>> list;
    private Context context;
    private LayoutInflater inflater;

    public GrzxAdapter(List<Map<String, Object>> list, Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHodler hodler = null;

        if (convertView==null){
            convertView = inflater.inflate(R.layout.gerenzhongxin_item,null);

            hodler = new ViewHodler();

            hodler.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            hodler.tv_title = (TextView) convertView.findViewById(R.id.tv_title);

            convertView.setTag(hodler);
        }else {
            hodler = (ViewHodler) convertView.getTag();
        }

        Map<String,Object> map = list.get(position);
        hodler.iv_img.setImageResource((int)map.get("image"));
        hodler.tv_title.setText((String)map.get("title"));
        return convertView;
    }

    class ViewHodler{
        ImageView iv_img;
        TextView tv_title;
    }

    public void setList(List<Map<String, Object>> list) {
        this.list = list;
    }
}
